package factory_method

import "fmt"

type IAnimal interface {
	SetName(name string)
	Call()
}

// 工厂方法接口
type IAnimalFactory interface {
	Create() IAnimal
}

type Animal struct {
	name string
}

func (a *Animal) SetName(name string) {
	a.name = name
}

// 子类工厂方法
type DogFactory struct {
}

func (DogFactory) Create() IAnimal{
	return &Dog{&Animal{}}
}

type Dog struct {
	*Animal
}

func (d *Dog) Call() {
	fmt.Println("汪汪汪...我叫" + d.name)
}

// 子类工厂方法
type CatFactory struct {
}

func (CatFactory) Create() IAnimal{
	return &Cat{&Animal{}}
}

type Cat struct {
	*Animal
}

func (d *Cat) Call() {
	fmt.Println("喵喵喵...我叫" + d.name)
}
